//
//  ThemeManager.m
//  LYPhotos
//
//  Created by 美鑫科技 on 16/5/5.
//  Copyright © 2016年 MorpLCP. All rights reserved.
//

#import "ThemeManager.h"

@implementation ThemeManager

- (instancetype)init{
    self = [super init];
    if (self) {
        self.theme = [Theme new];
        self.setSelfStyle = NO;
    }
    return self;
}

static ThemeManager *manager = nil;
+ (instancetype)shareManager{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [ThemeManager new];
    });
    return manager;
}

// 设置夜间 / 白天模式
- (void)changeShowMode:(ThemeStyle)mode{
    switch (mode) {
        case ThemeStyleForDaytimeMode:
        self.theme.themeBodyColor = [UIColor yellowColor];
        self.theme.themeColor = [UIColor greenColor];
        self.theme.themeTextColor = [UIColor purpleColor];
        [self.theme saveTheme:self.theme];
        break;
        case ThemeStyleForNightMode:
        self.theme.themeBodyColor = [UIColor grayColor];
        self.theme.themeColor = [UIColor blackColor];
        self.theme.themeTextColor = [UIColor whiteColor];
        [self.theme saveTheme:self.theme];
        break;
        default:
        break;
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeChange" object:@"mode"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeBodyChange" object:@"mode"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTextColor" object:@"mode"];
}

- (void)changeTheme:(Theme *)theme{
    self.theme = theme;
    [self.theme saveTheme:theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeChange" object:@"theme"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeBodyChange" object:@"theme"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTextColor" object:@"theme"];
}

// 单独设置主题(自定义)
- (void)changeThemeWithColor:(UIColor *)color{
    self.theme.themeImage = nil;
    self.theme.themeImageURL = nil;
    self.theme.themeColor = color;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeChange" object:@"color"];
}

- (void)changeThemeWithRandomColor{
    self.theme.themeImage = nil;
    self.theme.themeImageURL = nil;
    self.theme.themeColor = RANDOM_COLOR;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeChange" object:@"randomColor"];
}

- (void)changeThemeWithImage:(UIImage *)image{
    self.theme.themeImage = image;
    self.theme.themeImageURL = nil;
    self.theme.themeColor = nil;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeChange" object:@"themeImage"];
}

- (void)changeThemeWithImageURL:(NSString *)imageUrl{
    self.theme.themeImage = nil;
    self.theme.themeImageURL = imageUrl;
    self.theme.themeColor = nil;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeChange" object:@"themeImageUrl"];
}

- (void)changeThemeWithTextColor:(UIColor *)color{
    self.theme.themeTextColor = color;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTextColor" object:@"themeTextColor"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeChange" object:@"themeTextColor"];
}

// 单独设置页面主体
- (void)changeBodyStyleWithColor:(UIColor *)color{
    self.theme.themeBodyImage = nil;
    self.theme.themeBodyImageURL = nil;
    self.theme.themeBodyColor = color;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeBodyChange" object:@"color"];
}

- (void)changeBodyStyleWithRandomColor{
    self.theme.themeBodyImage = nil;
    self.theme.themeBodyImageURL = nil;
    self.theme.themeBodyColor = RANDOM_COLOR;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeBodyChange" object:@"randomColor"];
}

- (void)changeBodyStyleWithImage:(UIImage *)image{
    self.theme.themeBodyColor = nil;
    self.theme.themeBodyImageURL = nil;
    self.theme.themeBodyImage = image;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeBodyChange" object:@"themeImage"];
}

- (void)changeBodyStyleWithImageURL:(NSString *)imageUrl{
    self.theme.themeBodyColor = nil;
    self.theme.themeBodyImage = nil;
    self.theme.themeBodyImageURL = imageUrl;
    [self.theme saveTheme:self.theme];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"themeBodyChange" object:@"themeImageUrl"];
}


@end
